<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>用户查找</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/css/news.css"/>
    <style>
        li {
            list-style: inherit !important;
        }
    </style>
</head>

<body class="childrenBody">
<form class="layui-form" action="">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">人员查询</label>
            <div class="layui-input-inline">
                <input type="text" name="title" placeholder="请输入姓名或手机号" class="layui-input"
                       id="searchGoods">
            </div>

            <a class="layui-btn layui-btn-normal" lay-filter="search" id="" onclick="searchGoods()">立即查询</a>
        </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">查询结果</label>
            <div class="layui-input-inline">
                <select id="drpGoods" lay-search="required" lay-filter="drpGoods">
                    <option value="">请选择员工</option>
                </select>
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <a class="layui-btn layui-btn-normal" lay-filter="demo1" id="add">确认</a>
            <a class="layui-btn layui-btn-primary close">取消</a>
        </div>
    </div>
</form>
<script type="text/javascript" src="../../js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/wangEditor.js"></script>
<script type="text/javascript" src="../../js/basic.js"></script>
<script>


    function searchGoods() {
        var searchKey = $('#searchGoods').val();
        if (searchKey == "") {
            layer.msg("请输入姓名或手机号", {icon: 1});
            return;
        }
        var btvId = GetQueryString("btvId");
        $.ajax({
            type: "post",
            url: "/user/list",
            data: {
                searchKey: searchKey,
                btvId: btvId
            },
            dataType: "json",
            success: function (data) {
                if (data.status == 0) {
                    $("#drpGoods").empty();
                    var op = document.createElement("option");
                    op.text = "找到" + data.result.length + "个员工";
                    op.value = "";
                    document.getElementById("drpGoods").appendChild(op);
                    for (var i = 0; i < data.result.length; i++) {
                        var op = document.createElement("option");
                        op.text = data.result[i].nickname + "||" + data.result[i].phone;
                        op.value = data.result[i].id;
                        document.getElementById("drpGoods").appendChild(op);
                        console.log(op)
                    }
                    layui.form.render();

                } else {
                    layer.msg(data.msg, {icon: 1});
                }
            }
        });

    }


    layui.use(['form'], function () {
    });


    //点击取消关闭当前弹窗
    $(".close").click(function () {
//当你在iframe页面关闭自身时
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    });

    $("#add").click(function () {

        if ($("#drpGoods").val() == "") {
            layer.msg('请选择员工', {icon: 2});
            return;
        }
        layer.closeAll("iframe");
        //刷新父页面

        var ex = GetQueryString("ex");

        var options=$("#drpGoods option:selected");//获取当前选择项.
        var str=options.text();//获取当前选择项的文本.
       var arr= str.split("||");

        parent.getUser($("#drpGoods").val(), arr[0],ex);
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    });


</script>
</body>

</html>